package cn.rocky.pandacodegen.service.impl;

import cn.rocky.pandacodegen.common.enums.DbType;
import cn.rocky.pandacodegen.domain.dto.DatasourceConfigDTO;
import cn.rocky.pandacodegen.domain.entity.DatasourceConfig;
import cn.rocky.pandacodegen.mapper.DatasourceConfigMapper;
import cn.rocky.pandacodegen.service.DatasourceConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DatasourceConfigServiceImpl implements DatasourceConfigService {

    @Resource
    private DatasourceConfigMapper datasourceConfigMapper;

    @Override
    public void insert(DatasourceConfig config) {
        if (!DbType.containDbType(config.getDbType())) {
            throw new RuntimeException("该配置项不存在, 请填写符合配置项的暑假类型");
        }
        config.setDriverClass(DbType.getDbType(config.getDbType()).getDriverClass());
        datasourceConfigMapper.insert(config);
    }

    @Override
    public void update(DatasourceConfig config) {
        datasourceConfigMapper.update(config);
    }

    @Override
    public List<DatasourceConfig> listAll(DatasourceConfigDTO req) {
        return datasourceConfigMapper.listAll(req);
    }

    @Override
    public DatasourceConfig getById(int id) {
        return datasourceConfigMapper.getById(id);
    }

    @Override
    public void delete(int id) {
        datasourceConfigMapper.delete(id);
    }


}
